package com.xuecheng.media.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.base.model.RestResponse;
import com.xuecheng.media.model.dto.QueryMediaParamsDto;
import com.xuecheng.media.model.po.MediaFiles;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

public interface MediaFileService extends IService<MediaFiles> {
    MediaFiles upload(Long companyId,MultipartFile file,String objectName);

    MediaFiles saveMediaFilesToDb(Long companyId,String companyName,
            String filename,String bucket,String filePath,String md5,Long fileSize);

    PageResult<MediaFiles> page(Long companyId, PageParams pageParams, QueryMediaParamsDto paramsDto);

    RestResponse<String> deleteById(Long companyId, Long id);

    /**
     * 上传分块文件
     * @param file
     * @param fileMd5
     * @param chunk
     * @return
     */
    RestResponse<Boolean> uploadChunk(MultipartFile file, String fileMd5, Integer chunk);

    /**
     * 大文件上传前检查文件是否存在
     * @param fileMd5
     * @return
     */
    RestResponse<Boolean> checkFile(String fileMd5);

    /**
     * 分块文件上传前检查对应的分块是否存在
     * @param fileMd5
     * @param chunk
     * @return
     */
    RestResponse<Boolean> checkChunk(String fileMd5, Integer chunk);

    /**
     * 大文件上传后合并分块文件
     * @param fileMd5
     * @param fileName
     * @param chunkTotal
     * @return
     */
    RestResponse<Boolean> mergeChunks(Long companyId,String fileMd5, String fileName, Integer chunkTotal);

    /**
     * 从minio下载文件到本地
     * @param bucket
     * @param object
     * @return
     */
    File downloadFileFromMinio(String bucket,String object);

    /**
     * 删除minio中的文件
     * @param bucket
     * @param object
     * @return
     */
    boolean deleteFromMinio(String bucket,String object);

    /**
     * 将文件上传到minio
     * @param bucket
     * @param object
     * @param fileAbsolutePath
     * @param mimeType
     * @return
     */
    boolean uploadFileToMinio(String bucket,String object,
                              String fileAbsolutePath, String mimeType);

    /**
     * 根据扩展名获取mimeType
     * @param extension
     * @return
     */
    String getMimeType(String extension);
}
